/**
 * 
 */
package com.an.echo;

import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GenericFutureListener;

/**
 * @author Administrator
 *
 */
public class Client {

	public static final String HOST = "127.0.0.1";
	public static void main(String[] args) {

		EventLoopGroup group = new NioEventLoopGroup();
		Bootstrap bootstrap = new Bootstrap();
		bootstrap.group(group).channel(NioSocketChannel.class)
		.handler(new ChannelInitializer<SocketChannel>() {

			@Override
			protected void initChannel(SocketChannel ch) throws Exception {

				ch.pipeline().addLast(new MyClientHandler());
			}
		});
		
		System.out.println("客户端。。。OK");
		ChannelFuture channelFuture = bootstrap.connect(HOST, Server.PORT);
		channelFuture.addListener(new GenericFutureListener<Future<? super Void>>() {

			@Override
			public void operationComplete(Future<? super Void> future) throws Exception {
				boolean success = future.isSuccess();
				System.out.println(success);
			}
		});
//		channelFuture.
		try {
			// 关闭通道进行监听
			channelFuture.channel().closeFuture().sync();
		} catch (InterruptedException e) {
			e.printStackTrace();
			group.shutdownGracefully();
		}
		
	}

}
